﻿Public Class frmDonViTinh

    Private Sub frmDonViTinh_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadDanhSachLenLuoi()
    End Sub
    Public Sub LoadDanhSachLenLuoi()
        dgvDanhSachDVT.DataSource = DonViTinhDAO.selectALL()
    End Sub

    Private Sub btnThem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem.Click
        Dim dvt As New DonViTinhDTO
        dvt.MaDonViTinh = txtMaDonViTinh.Text
        dvt.TenDonViTinh = txtTenDonViTinh.Text
        DonViTinhDAO.insert(dvt)
        LoadDanhSachLenLuoi()
    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        Dim dvt As String
        dvt = txtMaDonViTinh.Text
        DonViTinhDAO.delete(dvt)
        LoadDanhSachLenLuoi()

    End Sub
    Public Sub HienThi()
        If dgvDanhSachDVT.SelectedRows.Count > 0 Then
            txtMaDonViTinh.Text = dgvDanhSachDVT.SelectedRows(0).Cells(0).Value.ToString()
            txtTenDonViTinh.Text = dgvDanhSachDVT.SelectedRows(0).Cells(1).Value.ToString()
        End If
    End Sub

    Private Sub dgvDanhSachDVT_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgvDanhSachDVT.SelectionChanged
        HienThi()
    End Sub

    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSua.Click
        Dim dvt As DonViTinhDTO = New DonViTinhDTO
        dvt.MaDonViTinh = txtMaDonViTinh.Text
        dvt.TenDonViTinh = txtTenDonViTinh.Text

        DonViTinhDAO.Update(dvt)
        LoadDanhSachLenLuoi()

    End Sub

   
End Class